package com.trinity.orders.controller;

import com.trinity.common.annotation.Log;
import com.trinity.common.core.controller.BaseController;
import com.trinity.common.core.domain.AjaxResult;
import com.trinity.common.core.page.TableDataInfo;
import com.trinity.common.enums.BusinessType;
import com.trinity.common.utils.poi.ExcelUtil;
import com.trinity.orders.domain.XcOrdersGoods;
import com.trinity.orders.service.IXcOrdersGoodsService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 订单详情Controller
 *
 * @author trinity
 * @date 2023-11-19
 */
@RestController
@RequestMapping("/order/goods")
public class XcOrdersGoodsController extends BaseController {
    @Resource
    private IXcOrdersGoodsService xcOrdersGoodsService;

    /**
     * 查询订单详情列表
     */
    @PreAuthorize("@ss.hasPermi('order:goods:list')")
    @GetMapping("/list")
    public TableDataInfo list(XcOrdersGoods xcOrdersGoods) {
        startPage();
        List<XcOrdersGoods> list = xcOrdersGoodsService.selectXcOrdersGoodsList(xcOrdersGoods);
        return getDataTable(list);
    }

    /**
     * 导出订单详情列表
     */
    @PreAuthorize("@ss.hasPermi('order:goods:export')")
    @Log(title = "订单详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XcOrdersGoods xcOrdersGoods) {
        List<XcOrdersGoods> list = xcOrdersGoodsService.selectXcOrdersGoodsList(xcOrdersGoods);
        ExcelUtil<XcOrdersGoods> util = new ExcelUtil<XcOrdersGoods>(XcOrdersGoods.class);
        util.exportExcel(response, list, "订单详情数据");
    }

    /**
     * 获取订单详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:goods:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(xcOrdersGoodsService.selectXcOrdersGoodsById(id));
    }

    /**
     * 新增订单详情
     */
    @PreAuthorize("@ss.hasPermi('order:goods:add')")
    @Log(title = "订单详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody XcOrdersGoods xcOrdersGoods) {
        return toAjax(xcOrdersGoodsService.insertXcOrdersGoods(xcOrdersGoods));
    }

    /**
     * 修改订单详情
     */
    @PreAuthorize("@ss.hasPermi('order:goods:edit')")
    @Log(title = "订单详情", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody XcOrdersGoods xcOrdersGoods) {
        return toAjax(xcOrdersGoodsService.updateXcOrdersGoods(xcOrdersGoods));
    }

    /**
     * 删除订单详情
     */
    @PreAuthorize("@ss.hasPermi('order:goods:remove')")
    @Log(title = "订单详情", businessType = BusinessType.DELETE)
    @PostMapping("/{ids}/delete")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(xcOrdersGoodsService.deleteXcOrdersGoodsByIds(ids));
    }
}
